package com.binarysoft.service.obj.dao;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO;
import static org.apache.ibatis.jdbc.SqlBuilder.SET;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.UPDATE;
import static org.apache.ibatis.jdbc.SqlBuilder.VALUES;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import com.binarysoft.service.obj.dao.ObjectEntity;

public class ObjectEntitySqlProvider {

    public String insertSelective(ObjectEntity record) {
        BEGIN();
        INSERT_INTO("object_entity");
        
        VALUES("obj_id", "#{objId,jdbcType=INTEGER}");
        
        if (record.getObjName() != null) {
            VALUES("obj_name", "#{objName,jdbcType=VARCHAR}");
        }
        
        if (record.getObjDesc() != null) {
            VALUES("obj_desc", "#{objDesc,jdbcType=VARCHAR}");
        }
        
        if (record.getObjAddr() != null) {
            VALUES("obj_addr", "#{objAddr,jdbcType=VARCHAR}");
        }
        
        VALUES("parent_obj_id", "#{parentObjId,jdbcType=INTEGER}");
        
        VALUES("root_obj_id", "#{rootObjId,jdbcType=INTEGER}");
        
        if (record.getObjHierarchy() != null) {
            VALUES("obj_hierarchy", "#{objHierarchy,jdbcType=INTEGER}");
        }
        
        if (record.getObjIndex() != null) {
            VALUES("obj_index", "#{objIndex,jdbcType=VARCHAR}");
        }
        
        if (record.getObjTypeId() != null) {
            VALUES("obj_type_id", "#{objTypeId,jdbcType=VARCHAR}");
        }
        
        if (record.getIsActive() != null) {
            VALUES("is_active", "#{isActive,jdbcType=BIT}");
        }
        
        if (record.getCreationTime() != null) {
            VALUES("creation_time", "#{creationTime,jdbcType=DATE}");
        }
        
        if (record.getLastUpdatedTime() != null) {
            VALUES("last_updated_time", "#{lastUpdatedTime,jdbcType=DATE}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(ObjectEntity record) {
        BEGIN();
        UPDATE("object_entity");
        
        if (record.getObjName() != null) {
            SET("obj_name = #{objName,jdbcType=VARCHAR}");
        }
        
        if (record.getObjDesc() != null) {
            SET("obj_desc = #{objDesc,jdbcType=VARCHAR}");
        }
        
        if (record.getObjAddr() != null) {
            SET("obj_addr = #{objAddr,jdbcType=VARCHAR}");
        }
        
        SET("parent_obj_id = #{parentObjId,jdbcType=INTEGER}");
        
        SET("root_obj_id = #{rootObjId,jdbcType=INTEGER}");
        
        if (record.getObjHierarchy() != null) {
            SET("obj_hierarchy = #{objHierarchy,jdbcType=INTEGER}");
        }
        
        if (record.getObjIndex() != null) {
            SET("obj_index = #{objIndex,jdbcType=VARCHAR}");
        }
        
        if (record.getObjTypeId() != null) {
            SET("obj_type_id = #{objTypeId,jdbcType=VARCHAR}");
        }
        
        if (record.getIsActive() != null) {
            SET("is_active = #{isActive,jdbcType=BIT}");
        }
        
        if (record.getCreationTime() != null) {
            SET("creation_time = #{creationTime,jdbcType=DATE}");
        }
        
        if (record.getLastUpdatedTime() != null) {
            SET("last_updated_time = #{lastUpdatedTime,jdbcType=DATE}");
        }
        
        WHERE("obj_id = #{objId,jdbcType=INTEGER}");
        
        return SQL();
    }
}